package o;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import java.io.Closeable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import o.fuc.c;

public class dvp {
    private static final Object ˎ = new byte[0];
    private static volatile dvp ॱ = null;
    private Context ʻ;
    private Handler ʼ;
    private Future<?> ʽ;
    private ExecutorService ˊ;
    private long ˋ;
    private long ˏ;
    private int ॱॱ;
    private volatile boolean ᐝ;

    class a implements Runnable {
        private String ˋ;
        final /* synthetic */ dvp ॱ;

        public a(dvp o_dvp, String str) {
            this.ॱ = o_dvp;
            this.ˋ = str;
        }

        public void run() {
            Closeable closeable = null;
            try {
                fuv ॱ = dnb.ॱ();
                o.fus.a ˏ = new o.fus.a().ˎ(this.ˋ).ˏ(new c().ˎ().ˊ());
                ˏ.ॱ("Range", "bytes=0-0").ॱ("Accept-Encoding", "identity").ॱ("Cache-Control", "no-cache");
                ˏ.ˋ(true);
                closeable = ॱ.ˎ(ˏ.ॱ()).execute();
                this.ॱ.ˋ = System.currentTimeMillis();
                Logger.ˎ("AheadConnection", "successfully do aheadConnection at : " + this.ॱ.ˋ);
            } catch (Exception e) {
                Logger.e("AheadConnection", "try to do aheadConnection fail! " + e.getMessage());
            } finally {
                dnw.ˎ(closeable);
            }
        }
    }

    protected dvp() {
        this.ˊ = null;
        this.ˏ = -1;
        this.ˋ = 0;
        this.ᐝ = false;
        this.ॱॱ = 0;
        this.ˊ = Executors.newSingleThreadExecutor();
    }

    public static dvp ˊ() {
        if (ॱ == null) {
            synchronized (dvp.class) {
                if (ॱ == null) {
                    ॱ = new dvp();
                }
            }
        }
        return ॱ;
    }

    public static boolean ॱ(Context context) {
        return !epw.ॱ(context, context.getPackageName());
    }

    public static boolean ˋ(Context context) {
        return doo.ॱॱ(context.getApplicationContext()) && !doo.ᐝ(context);
    }

    private Handler ˏ() {
        return new Handler(this) {
            final /* synthetic */ dvp ॱ;

            {
                this.ॱ = r1;
            }

            public void handleMessage(Message message) {
                if (message.what == 1111 && dno.c.ॱ(message.arg1) == dno.c.CONNECTED && this.ॱ.ʻ != null) {
                    dvp.ˊ().ॱ(this.ॱ.ʻ, false);
                }
            }
        };
    }

    public void ˎ(Context context) {
        synchronized (ˎ) {
            if (!this.ᐝ) {
                this.ʻ = context.getApplicationContext();
                if (this.ʼ == null) {
                    this.ʼ = ˏ();
                }
                dno.ॱ().ˋ(this.ʼ, 1111);
                this.ᐝ = true;
                Logger.ˎ("AheadConnection", "register networkchange handler for aheadconnection");
            }
        }
    }

    public void ˋ() {
        synchronized (ˎ) {
            dno.ॱ().ॱ(this.ʼ);
            this.ᐝ = false;
            Logger.ˎ("AheadConnection", "unregister networkchange handler for aheadconnection");
        }
    }

    public void ˎ(int i) {
        synchronized (ˎ) {
            this.ॱॱ = i;
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void ॱ(android.content.Context r7, boolean r8) {
        /*
        r6 = this;
        r1 = ˎ;
        monitor-enter(r1);
        r2 = r6.ˏ;	 Catch:{ all -> 0x0018 }
        r4 = 5000; // 0x1388 float:7.006E-42 double:2.4703E-320;
        r2 = r2 + r4;
        r4 = java.lang.System.currentTimeMillis();	 Catch:{ all -> 0x0018 }
        r0 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1));
        if (r0 <= 0) goto L_0x0012;
    L_0x0010:
        monitor-exit(r1);	 Catch:{ all -> 0x0018 }
    L_0x0011:
        return;
    L_0x0012:
        r0 = r6.ॱॱ;	 Catch:{ all -> 0x0018 }
        if (r0 != 0) goto L_0x001b;
    L_0x0016:
        monitor-exit(r1);	 Catch:{ all -> 0x0018 }
        goto L_0x0011;
    L_0x0018:
        r0 = move-exception;
        monitor-exit(r1);	 Catch:{ all -> 0x0018 }
        throw r0;
    L_0x001b:
        r0 = ॱ(r7);	 Catch:{ all -> 0x0018 }
        if (r0 == 0) goto L_0x0023;
    L_0x0021:
        monitor-exit(r1);	 Catch:{ all -> 0x0018 }
        goto L_0x0011;
    L_0x0023:
        r0 = ˋ(r7);	 Catch:{ all -> 0x0018 }
        if (r0 != 0) goto L_0x002b;
    L_0x0029:
        monitor-exit(r1);	 Catch:{ all -> 0x0018 }
        goto L_0x0011;
    L_0x002b:
        r0 = o.dvt.ˏ();	 Catch:{ all -> 0x0018 }
        r0 = r0.ॱॱ();	 Catch:{ all -> 0x0018 }
        if (r0 == 0) goto L_0x0037;
    L_0x0035:
        monitor-exit(r1);	 Catch:{ all -> 0x0018 }
        goto L_0x0011;
    L_0x0037:
        r0 = r6.ˊ(r8);	 Catch:{ all -> 0x0018 }
        if (r0 != 0) goto L_0x003f;
    L_0x003d:
        monitor-exit(r1);	 Catch:{ all -> 0x0018 }
        goto L_0x0011;
    L_0x003f:
        r0 = "ahead.conn.url";
        r0 = o.cvx.ˎ(r0);	 Catch:{ all -> 0x0018 }
        r2 = android.text.TextUtils.isEmpty(r0);	 Catch:{ all -> 0x0018 }
        if (r2 == 0) goto L_0x004d;
    L_0x004b:
        monitor-exit(r1);	 Catch:{ all -> 0x0018 }
        goto L_0x0011;
    L_0x004d:
        r2 = r6.ʽ;	 Catch:{ all -> 0x0018 }
        if (r2 == 0) goto L_0x0059;
    L_0x0051:
        r2 = r6.ʽ;	 Catch:{ all -> 0x0018 }
        r2 = r2.isDone();	 Catch:{ all -> 0x0018 }
        if (r2 == 0) goto L_0x006c;
    L_0x0059:
        r2 = java.lang.System.currentTimeMillis();	 Catch:{ all -> 0x0018 }
        r6.ˏ = r2;	 Catch:{ all -> 0x0018 }
        r2 = r6.ˊ;	 Catch:{ all -> 0x0018 }
        r3 = new o.dvp$a;	 Catch:{ all -> 0x0018 }
        r3.<init>(r6, r0);	 Catch:{ all -> 0x0018 }
        r0 = r2.submit(r3);	 Catch:{ all -> 0x0018 }
        r6.ʽ = r0;	 Catch:{ all -> 0x0018 }
    L_0x006c:
        monitor-exit(r1);	 Catch:{ all -> 0x0018 }
        goto L_0x0011;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.dvp.ॱ(android.content.Context, boolean):void");
    }

    private boolean ˊ(boolean z) {
        if (!z || System.currentTimeMillis() >= 595000 + this.ˋ) {
            return true;
        }
        return false;
    }
}
